package com.hllxd.hism.star.basic.service.controller2;

import com.hllxd.hism.framework.httprpc.service.*;
import com.hllxd.hism.star.basic.service.exception.BusinessException;
import com.hllxd.hism.star.basic.service.model.VersionEntity;
import com.hllxd.hism.star.basic.service.service.VersionService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xiyong.lxy
 * @date 2020-10-12 16:51
 */
@Slf4j
@RestGrpcService
@RestGrpcMapping("/v1/version")
public class VersionController2 {


    @Autowired
    private VersionService versionService;
    @Data
    public static class Params {
        private Integer p1;
        private String appid;
        private String p2;
        private String p3;
    }

    @RestGrpcMapping("/list.do")
    public NTSTATUS list(PDRIVER_OBJECT params, PRESULT_OBJECT result) {
        log.info("params: {}", params);
        try {
            Params aa = params.driverObject(Params.class);
            List<VersionEntity> items = versionService.list(aa.appid);
            result.setData(items);
            return NTSTATUS.SUCCESS_STATUS();
        }catch (BusinessException e) {
            log.warn("Exception: {}. {}",e.toString(), params);
            return NTSTATUS.ERROR_STATUS(e.code, e.msg);
        }catch (Exception e) {
            log.error("Exception: {}. {}",e.toString(),params, e);
            return NTSTATUS.ERROR_STATUS("500", e.toString());
        }
    }
}
